{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "ru_CLIP_tiny_onnx.ipynb",
      "provenance": [],
      "collapsed_sections": [
        "WWXCt_2NLhN_",
        "PHb4CAoRL3qC",
        "re2sSYAYO3D-",
        "ithu4-z0PIm5",
        "FWm0GAhWPzSW"
      ],
      "machine_shape": "hm"
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    },
    "accelerator": "GPU",
    "widgets": {
      "application/vnd.jupyter.widget-state+json": {
        "5319c7971f234d4bb615508f76475f9e": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HBoxModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "HBoxView",
            "_dom_classes": [],
            "_model_name": "HBoxModel",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "box_style": "",
            "layout": "IPY_MODEL_c43027a0735e459ca1f710e5a9c43177",
            "_model_module": "@jupyter-widgets/controls",
            "children": [
              "IPY_MODEL_c00c959249db4f2a9b97adabd2684c3c",
              "IPY_MODEL_d9e4edd05c1e40f991eb2c2f1fc9ebc1",
              "IPY_MODEL_ab4928c0a86449a384e36d8c0bc25717"
            ]
          }
        },
        "c43027a0735e459ca1f710e5a9c43177": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "c00c959249db4f2a9b97adabd2684c3c": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_3251223dac8f43c081701ff7f663cb35",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": "Downloading: 100%",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_d63d5559ce534b86969132d3ff8d875b"
          }
        },
        "d9e4edd05c1e40f991eb2c2f1fc9ebc1": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "FloatProgressModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "ProgressView",
            "style": "IPY_MODEL_59618f021fc4495e9c401a421d28d4a0",
            "_dom_classes": [],
            "description": "",
            "_model_name": "FloatProgressModel",
            "bar_style": "success",
            "max": 381781,
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": 381781,
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "orientation": "horizontal",
            "min": 0,
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_c56ba935682647dca4bdcc593fe0d2cc"
          }
        },
        "ab4928c0a86449a384e36d8c0bc25717": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_01808c7fec8447368d60a33b2d683851",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": " 373k/373k [00:00&lt;00:00, 876kB/s]",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_f9466e0349c84633a0fb8ceeffa2a984"
          }
        },
        "3251223dac8f43c081701ff7f663cb35": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "d63d5559ce534b86969132d3ff8d875b": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "59618f021fc4495e9c401a421d28d4a0": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "ProgressStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "bar_color": null,
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "c56ba935682647dca4bdcc593fe0d2cc": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "01808c7fec8447368d60a33b2d683851": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "f9466e0349c84633a0fb8ceeffa2a984": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "10ee9777b41e42129e2c9cc9327ad88f": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HBoxModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "HBoxView",
            "_dom_classes": [],
            "_model_name": "HBoxModel",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "box_style": "",
            "layout": "IPY_MODEL_cb6a647757244da3941602127ec38ccb",
            "_model_module": "@jupyter-widgets/controls",
            "children": [
              "IPY_MODEL_a64a223312144f2f9736729b63ab1ce5",
              "IPY_MODEL_7e7bce13eeed41179e4e15fc7afc89d5",
              "IPY_MODEL_7bacd13c23cf415fa5d58e9243c4a785"
            ]
          }
        },
        "cb6a647757244da3941602127ec38ccb": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "a64a223312144f2f9736729b63ab1ce5": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_9fe6e1167e5d45fbad2adab3d59e017d",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": "Downloading: 100%",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_655c507d8fcf423f8bd6746201f569ae"
          }
        },
        "7e7bce13eeed41179e4e15fc7afc89d5": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "FloatProgressModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "ProgressView",
            "style": "IPY_MODEL_8c4812afaaec4d65bf84a1e77840d356",
            "_dom_classes": [],
            "description": "",
            "_model_name": "FloatProgressModel",
            "bar_style": "success",
            "max": 112,
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": 112,
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "orientation": "horizontal",
            "min": 0,
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_64dfa71e3dff4236908e0592e4f90250"
          }
        },
        "7bacd13c23cf415fa5d58e9243c4a785": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_ec8d98c1edb148d3ae1c518b61e8155b",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": " 112/112 [00:00&lt;00:00, 3.41kB/s]",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_a8212828565d4c9884d44fb45dc51ee5"
          }
        },
        "9fe6e1167e5d45fbad2adab3d59e017d": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "655c507d8fcf423f8bd6746201f569ae": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "8c4812afaaec4d65bf84a1e77840d356": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "ProgressStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "bar_color": null,
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "64dfa71e3dff4236908e0592e4f90250": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "ec8d98c1edb148d3ae1c518b61e8155b": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "a8212828565d4c9884d44fb45dc51ee5": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "9a2d4d7da3024cc0828b1a6dafd0dd16": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HBoxModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "HBoxView",
            "_dom_classes": [],
            "_model_name": "HBoxModel",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "box_style": "",
            "layout": "IPY_MODEL_fe4daa4d7d024187aa2f622dbf3577a8",
            "_model_module": "@jupyter-widgets/controls",
            "children": [
              "IPY_MODEL_8380bf9a899645e8aef576e640b41ea2",
              "IPY_MODEL_37c593d2f442497483cd0026498bab05",
              "IPY_MODEL_3cc7b132c94f427ba44858e4c4ce3019"
            ]
          }
        },
        "fe4daa4d7d024187aa2f622dbf3577a8": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "8380bf9a899645e8aef576e640b41ea2": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_d2aed3c0f95b4677bd6e949a4ed0403e",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": "Downloading: 100%",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_bbc52e0e0b2f4758bd7d6cf44b4670ae"
          }
        },
        "37c593d2f442497483cd0026498bab05": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "FloatProgressModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "ProgressView",
            "style": "IPY_MODEL_8513d262d8764d99aa5d3f2f178b875e",
            "_dom_classes": [],
            "description": "",
            "_model_name": "FloatProgressModel",
            "bar_style": "success",
            "max": 239,
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": 239,
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "orientation": "horizontal",
            "min": 0,
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_57984bbd46a84a7bb2b7629e6b2f9ef9"
          }
        },
        "3cc7b132c94f427ba44858e4c4ce3019": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_b886e2b6bbcd46cf806ff3a0b3cb8d33",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": " 239/239 [00:00&lt;00:00, 5.49kB/s]",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_21ac91113f7e4548b416a32b1b3f66a9"
          }
        },
        "d2aed3c0f95b4677bd6e949a4ed0403e": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "bbc52e0e0b2f4758bd7d6cf44b4670ae": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "8513d262d8764d99aa5d3f2f178b875e": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "ProgressStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "bar_color": null,
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "57984bbd46a84a7bb2b7629e6b2f9ef9": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "b886e2b6bbcd46cf806ff3a0b3cb8d33": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "21ac91113f7e4548b416a32b1b3f66a9": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "f8958c6de2394fecab9f95388a365431": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HBoxModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "HBoxView",
            "_dom_classes": [],
            "_model_name": "HBoxModel",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "box_style": "",
            "layout": "IPY_MODEL_11a8a4b2d39d4ea8904c0f1b2f6dd906",
            "_model_module": "@jupyter-widgets/controls",
            "children": [
              "IPY_MODEL_9657501af7514a60b30fcd60a223980c",
              "IPY_MODEL_61274b2bac5e4835a8bd33dc201bc155",
              "IPY_MODEL_973300b095554b10ac290244772e0a6f"
            ]
          }
        },
        "11a8a4b2d39d4ea8904c0f1b2f6dd906": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "9657501af7514a60b30fcd60a223980c": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_c3f5f56bb14d44b6a5775a77f6763b94",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": "Downloading: 100%",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_fbf430940c8a49949953155b57d07766"
          }
        },
        "61274b2bac5e4835a8bd33dc201bc155": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "FloatProgressModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "ProgressView",
            "style": "IPY_MODEL_ab05641bcb9c49aab977110fab503a78",
            "_dom_classes": [],
            "description": "",
            "_model_name": "FloatProgressModel",
            "bar_style": "success",
            "max": 175,
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": 175,
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "orientation": "horizontal",
            "min": 0,
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_4f11a71d7df943e48ac9ea3bab5c6771"
          }
        },
        "973300b095554b10ac290244772e0a6f": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "HTMLView",
            "style": "IPY_MODEL_b6004e09152045e18503cf75e32d4fa6",
            "_dom_classes": [],
            "description": "",
            "_model_name": "HTMLModel",
            "placeholder": "​",
            "_view_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "value": " 175/175 [00:00&lt;00:00, 5.41kB/s]",
            "_view_count": null,
            "_view_module_version": "1.5.0",
            "description_tooltip": null,
            "_model_module": "@jupyter-widgets/controls",
            "layout": "IPY_MODEL_590fb707d26948b5b9c8bb3b896f29e1"
          }
        },
        "c3f5f56bb14d44b6a5775a77f6763b94": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "fbf430940c8a49949953155b57d07766": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "ab05641bcb9c49aab977110fab503a78": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "ProgressStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "bar_color": null,
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "4f11a71d7df943e48ac9ea3bab5c6771": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        },
        "b6004e09152045e18503cf75e32d4fa6": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "model_module_version": "1.5.0",
          "state": {
            "_view_name": "StyleView",
            "_model_name": "DescriptionStyleModel",
            "description_width": "",
            "_view_module": "@jupyter-widgets/base",
            "_model_module_version": "1.5.0",
            "_view_count": null,
            "_view_module_version": "1.2.0",
            "_model_module": "@jupyter-widgets/controls"
          }
        },
        "590fb707d26948b5b9c8bb3b896f29e1": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_view_name": "LayoutView",
            "grid_template_rows": null,
            "right": null,
            "justify_content": null,
            "_view_module": "@jupyter-widgets/base",
            "overflow": null,
            "_model_module_version": "1.2.0",
            "_view_count": null,
            "flex_flow": null,
            "width": null,
            "min_width": null,
            "border": null,
            "align_items": null,
            "bottom": null,
            "_model_module": "@jupyter-widgets/base",
            "top": null,
            "grid_column": null,
            "overflow_y": null,
            "overflow_x": null,
            "grid_auto_flow": null,
            "grid_area": null,
            "grid_template_columns": null,
            "flex": null,
            "_model_name": "LayoutModel",
            "justify_items": null,
            "grid_row": null,
            "max_height": null,
            "align_content": null,
            "visibility": null,
            "align_self": null,
            "height": null,
            "min_height": null,
            "padding": null,
            "grid_auto_rows": null,
            "grid_gap": null,
            "max_width": null,
            "order": null,
            "_view_module_version": "1.2.0",
            "grid_template_areas": null,
            "object_position": null,
            "object_fit": null,
            "grid_auto_columns": null,
            "margin": null,
            "display": null,
            "left": null
          }
        }
      }
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/cene555/ru-clip-tiny/blob/main/notebooks/ru_CLIP_tiny_onnx.ipynb)"
      ],
      "metadata": {
        "id": "JsWuTduwaagq"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Select a runtime GPU to continue:\n",
        "\n",
        "Click Runtime -> Change Runtime Type -> switch \"Harware accelerator\" to be GPU. Save it, and you maybe connect to GPU"
      ],
      "metadata": {
        "id": "VCCzmQdKJPkv"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "#@title Allowed Resources\n",
        "import multiprocessing\n",
        "import torch\n",
        "from psutil import virtual_memory\n",
        "\n",
        "ram_gb = round(virtual_memory().total / 1024**3, 1)\n",
        "\n",
        "print('CPU:', multiprocessing.cpu_count())\n",
        "print('RAM GB:', ram_gb)\n",
        "print(\"PyTorch version:\", torch.__version__)\n",
        "print(\"CUDA version:\", torch.version.cuda)\n",
        "print(\"cuDNN version:\", torch.backends.cudnn.version())\n",
        "device = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")\n",
        "print(\"device:\", device.type)\n",
        "\n",
        "!nvidia-smi"
      ],
      "metadata": {
        "cellView": "form",
        "id": "6xdy_cPJEYXV",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "9b5c5751-3377-4623-fd90-f59c21118c80"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "CPU: 2\n",
            "RAM GB: 12.7\n",
            "PyTorch version: 1.10.0+cu111\n",
            "CUDA version: 11.1\n",
            "cuDNN version: 8005\n",
            "device: cuda\n",
            "Tue Feb  1 17:26:24 2022       \n",
            "+-----------------------------------------------------------------------------+\n",
            "| NVIDIA-SMI 495.46       Driver Version: 460.32.03    CUDA Version: 11.2     |\n",
            "|-------------------------------+----------------------+----------------------+\n",
            "| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |\n",
            "| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |\n",
            "|                               |                      |               MIG M. |\n",
            "|===============================+======================+======================|\n",
            "|   0  Tesla T4            Off  | 00000000:00:04.0 Off |                    0 |\n",
            "| N/A   61C    P8    11W /  70W |      3MiB / 15109MiB |      0%      Default |\n",
            "|                               |                      |                  N/A |\n",
            "+-------------------------------+----------------------+----------------------+\n",
            "                                                                               \n",
            "+-----------------------------------------------------------------------------+\n",
            "| Processes:                                                                  |\n",
            "|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |\n",
            "|        ID   ID                                                   Usage      |\n",
            "|=============================================================================|\n",
            "|  No running processes found                                                 |\n",
            "+-----------------------------------------------------------------------------+\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Restart colab session after installation\n",
        "Reload session if something doesn't work (may need multiple times)"
      ],
      "metadata": {
        "id": "hmNP7iJBj6XZ"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Install requirements"
      ],
      "metadata": {
        "id": "WWXCt_2NLhN_"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "%%capture\n",
        "!gdown -O ru-clip-tiny.pkl https://drive.google.com/uc?id=1-3g3J90pZmHo9jbBzsEmr7ei5zm3VXOL\n",
        "\n",
        "!pip install git+https://github.com/cene555/ru-clip-tiny.git\n",
        "!pip install git+https://github.com/Lednik7/CLIP-ONNX.git\n",
        "!pip install onnxruntime-gpu\n",
        "\n",
        "!wget -c -O CLIP.png https://github.com/openai/CLIP/blob/main/CLIP.png?raw=true"
      ],
      "metadata": {
        "id": "FWEEtd7Vryaf"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "import onnxruntime\n",
        "\n",
        "# priority device (if available)\n",
        "print(onnxruntime.get_device())"
      ],
      "metadata": {
        "id": "bUFx02Dhjap4",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "f595c387-da47-47e5-f96a-2d84adf3286b"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "GPU\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Import libraries"
      ],
      "metadata": {
        "id": "PHb4CAoRL3qC"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import torch\n",
        "from rucliptiny import RuCLIPtiny\n",
        "from rucliptiny.utils import get_transform\n",
        "from rucliptiny.tokenizer import Tokenizer"
      ],
      "metadata": {
        "id": "cznZ7ozDL5-M"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "import warnings\n",
        "\n",
        "warnings.filterwarnings(\"ignore\", category=UserWarning)"
      ],
      "metadata": {
        "id": "57COx0BKCmFA"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Load model"
      ],
      "metadata": {
        "id": "ithu4-z0PIm5"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "#@title speed_test function\n",
        "\n",
        "import time\n",
        "\n",
        "def speed_test(func, data_gen, n=5, empty_cache=True, is_text=False,\n",
        "               first_run=True):\n",
        "    if empty_cache: torch.cuda.empty_cache()\n",
        "    if first_run:\n",
        "        if is_text:\n",
        "            input_data1, input_data2 = data_gen()\n",
        "            func(input_data1, input_data2)\n",
        "        else:\n",
        "            input_data = data_gen()\n",
        "            func(input_data)\n",
        "        torch.cuda.empty_cache()\n",
        "    \n",
        "    values = []\n",
        "    for _ in range(n):\n",
        "        if is_text:\n",
        "            input_data1, input_data2 = data_gen()\n",
        "        else:\n",
        "            input_data = data_gen()\n",
        "        if is_text:\n",
        "            t = time.time()\n",
        "            func(input_data1, input_data2)\n",
        "        else:\n",
        "            t = time.time()\n",
        "            func(input_data)\n",
        "        values.append(time.time() - t)\n",
        "        if empty_cache: torch.cuda.empty_cache()\n",
        "    return sum(values) / n"
      ],
      "metadata": {
        "id": "GqKM04tP4Vv3",
        "cellView": "form"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "torch.manual_seed(1)\n",
        "device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')"
      ],
      "metadata": {
        "id": "SSOHYDRQGif-"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "model = RuCLIPtiny()\n",
        "model.load_state_dict(torch.load('ru-clip-tiny.pkl',\n",
        "                                 map_location=device))\n",
        "model = model.to(device).eval()\n",
        "for x in model.parameters(): x.requires_grad = False\n",
        "torch.cuda.empty_cache()"
      ],
      "metadata": {
        "id": "OpFAZfq-_nJe"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "transforms = get_transform()\n",
        "tokenizer = Tokenizer()"
      ],
      "metadata": {
        "id": "KEZj2WrwkzZz",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 145,
          "referenced_widgets": [
            "5319c7971f234d4bb615508f76475f9e",
            "c43027a0735e459ca1f710e5a9c43177",
            "c00c959249db4f2a9b97adabd2684c3c",
            "d9e4edd05c1e40f991eb2c2f1fc9ebc1",
            "ab4928c0a86449a384e36d8c0bc25717",
            "3251223dac8f43c081701ff7f663cb35",
            "d63d5559ce534b86969132d3ff8d875b",
            "59618f021fc4495e9c401a421d28d4a0",
            "c56ba935682647dca4bdcc593fe0d2cc",
            "01808c7fec8447368d60a33b2d683851",
            "f9466e0349c84633a0fb8ceeffa2a984",
            "10ee9777b41e42129e2c9cc9327ad88f",
            "cb6a647757244da3941602127ec38ccb",
            "a64a223312144f2f9736729b63ab1ce5",
            "7e7bce13eeed41179e4e15fc7afc89d5",
            "7bacd13c23cf415fa5d58e9243c4a785",
            "9fe6e1167e5d45fbad2adab3d59e017d",
            "655c507d8fcf423f8bd6746201f569ae",
            "8c4812afaaec4d65bf84a1e77840d356",
            "64dfa71e3dff4236908e0592e4f90250",
            "ec8d98c1edb148d3ae1c518b61e8155b",
            "a8212828565d4c9884d44fb45dc51ee5",
            "9a2d4d7da3024cc0828b1a6dafd0dd16",
            "fe4daa4d7d024187aa2f622dbf3577a8",
            "8380bf9a899645e8aef576e640b41ea2",
            "37c593d2f442497483cd0026498bab05",
            "3cc7b132c94f427ba44858e4c4ce3019",
            "d2aed3c0f95b4677bd6e949a4ed0403e",
            "bbc52e0e0b2f4758bd7d6cf44b4670ae",
            "8513d262d8764d99aa5d3f2f178b875e",
            "57984bbd46a84a7bb2b7629e6b2f9ef9",
            "b886e2b6bbcd46cf806ff3a0b3cb8d33",
            "21ac91113f7e4548b416a32b1b3f66a9",
            "f8958c6de2394fecab9f95388a365431",
            "11a8a4b2d39d4ea8904c0f1b2f6dd906",
            "9657501af7514a60b30fcd60a223980c",
            "61274b2bac5e4835a8bd33dc201bc155",
            "973300b095554b10ac290244772e0a6f",
            "c3f5f56bb14d44b6a5775a77f6763b94",
            "fbf430940c8a49949953155b57d07766",
            "ab05641bcb9c49aab977110fab503a78",
            "4f11a71d7df943e48ac9ea3bab5c6771",
            "b6004e09152045e18503cf75e32d4fa6",
            "590fb707d26948b5b9c8bb3b896f29e1"
          ]
        },
        "outputId": "466854ba-7fa2-4154-ada2-391626146c95"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "application/vnd.jupyter.widget-view+json": {
              "model_id": "5319c7971f234d4bb615508f76475f9e",
              "version_minor": 0,
              "version_major": 2
            },
            "text/plain": [
              "Downloading:   0%|          | 0.00/373k [00:00<?, ?B/s]"
            ]
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "application/vnd.jupyter.widget-view+json": {
              "model_id": "10ee9777b41e42129e2c9cc9327ad88f",
              "version_minor": 0,
              "version_major": 2
            },
            "text/plain": [
              "Downloading:   0%|          | 0.00/112 [00:00<?, ?B/s]"
            ]
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "application/vnd.jupyter.widget-view+json": {
              "model_id": "9a2d4d7da3024cc0828b1a6dafd0dd16",
              "version_minor": 0,
              "version_major": 2
            },
            "text/plain": [
              "Downloading:   0%|          | 0.00/239 [00:00<?, ?B/s]"
            ]
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "application/vnd.jupyter.widget-view+json": {
              "model_id": "f8958c6de2394fecab9f95388a365431",
              "version_minor": 0,
              "version_major": 2
            },
            "text/plain": [
              "Downloading:   0%|          | 0.00/175 [00:00<?, ?B/s]"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## [Speed test] Batch 64"
      ],
      "metadata": {
        "id": "BGsIitOkCCLE"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "speed_test(model.encode_image, lambda: torch.randint(1, 255, (64, 3, 224, 224)).to(device))"
      ],
      "metadata": {
        "id": "5Ii9OlgUjR9J",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "21f1c03c-3e45-4650-d892-be2d83021d21"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0.011787748336791993"
            ]
          },
          "metadata": {},
          "execution_count": 7
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "speed_test(model.encode_text,\n",
        "           lambda: (torch.randint(1, 255, (64, 77)).to(device),\n",
        "                    torch.randint(0, 2, (64, 77)).to(device)),\n",
        "           is_text=True)"
      ],
      "metadata": {
        "id": "3Ho_rGd6j0_8",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "1026df31-ea4b-4f50-e76d-f300bee0299a"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0.004021787643432617"
            ]
          },
          "metadata": {},
          "execution_count": 8
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Prepare functions"
      ],
      "metadata": {
        "id": "81uWLBrMkl3T"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from PIL import Image\n",
        "import numpy as np"
      ],
      "metadata": {
        "id": "ry5BqVbzk-gM"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# batch first\n",
        "image = transforms(Image.open(\"CLIP.png\")).unsqueeze(0).cpu() # [1, 3, 224, 224]\n",
        "\n",
        "# batch first\n",
        "texts = ['диаграмма', 'собака', 'кошка']\n",
        "text_tokens, attention_mask = tokenizer.tokenize(texts, max_len=77)\n",
        "text_tokens, attention_mask = text_tokens.cpu(), attention_mask.cpu() # [3, 77]\n",
        "\n",
        "# batch second\n",
        "dummy_input_text = torch.stack([text_tokens, attention_mask]).detach().cpu()"
      ],
      "metadata": {
        "id": "jyE4C7nIkT_5"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "text_tokens_onnx = text_tokens.detach().cpu().numpy().astype(np.int64)\n",
        "attention_mask_onnx = attention_mask.detach().cpu().numpy().astype(np.int64)\n",
        "\n",
        "image_onnx = image.detach().cpu().numpy().astype(np.float32)\n",
        "text_onnx = torch.stack([text_tokens, attention_mask]).detach().cpu()\\\n",
        "                                                    .numpy().astype(np.int64)"
      ],
      "metadata": {
        "id": "9SJJmuuWlSjS"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Convert RuCLIP model to ONNX"
      ],
      "metadata": {
        "id": "Y7V4BjOGkRcu"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "class Textual(torch.nn.Module):\n",
        "    def __init__(self, model):\n",
        "        super().__init__()\n",
        "        self.model = model\n",
        "\n",
        "    def forward(self, input_data):\n",
        "        input_ids, attention_mask = input_data\n",
        "        x = self.model.transformer(input_ids=input_ids, attention_mask=attention_mask)\n",
        "        x = x.last_hidden_state[:, 0, :]\n",
        "        x = self.model.final_ln(x)\n",
        "        return x"
      ],
      "metadata": {
        "id": "HzGiuIo8m341"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "from clip_onnx import clip_onnx\n",
        "from clip_onnx.utils import DEFAULT_EXPORT\n",
        "\n",
        "visual_path = \"clip_visual.onnx\"\n",
        "textual_path = \"clip_textual.onnx\"\n",
        "\n",
        "textual_export_params = DEFAULT_EXPORT.copy()\n",
        "textual_export_params[\"dynamic_axes\"] = {'input': {1: 'batch_size'},\n",
        "                                         'output': {0: 'batch_size'}}\n",
        "\n",
        "onnx_model = clip_onnx(model.cpu(), visual_path=visual_path, textual_path=textual_path)\n",
        "onnx_model.convert2onnx(image, dummy_input_text, verbose=True,\n",
        "                        textual_wrapper=Textual,\n",
        "                        textual_export_params=textual_export_params)"
      ],
      "metadata": {
        "id": "k5eQK8gJla5a",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "09ec9b1d-70f0-4d01-87be-5bb622c14e89"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[CLIP ONNX] Start convert visual model\n",
            "[CLIP ONNX] Start check visual model\n",
            "[CLIP ONNX] Start convert textual model\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:7: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).\n",
            "  import sys\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[CLIP ONNX] Start check textual model\n",
            "[CLIP ONNX] Models converts successfully\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## [ONNX] CUDA inference mode"
      ],
      "metadata": {
        "id": "QQ0A0gUFzQr-"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Optional cell, can be skipped\n",
        "\n",
        "visual_path = \"clip_visual.onnx\"\n",
        "textual_path = \"clip_textual.onnx\"\n",
        "\n",
        "onnx_model.load_onnx(visual_path,\n",
        "                     textual_path,\n",
        "                     29.9119) # model.logit_scale.exp()"
      ],
      "metadata": {
        "id": "YR-Pv3E8q_mz"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# ['TensorrtExecutionProvider', 'CUDAExecutionProvider', 'CPUExecutionProvider']\n",
        "onnx_model.start_sessions(providers=[\"CUDAExecutionProvider\"]) # cuda mode"
      ],
      "metadata": {
        "id": "J2qxXvmfo2eu"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "onnx_model.visual_session.get_providers()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "yq05H9f7vyQy",
        "outputId": "2c39c48b-db02-4610-addd-901429497a43"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "['CUDAExecutionProvider', 'CPUExecutionProvider']"
            ]
          },
          "metadata": {},
          "execution_count": 16
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## [Speed test] Batch 64"
      ],
      "metadata": {
        "id": "EieJHr_CA2ui"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "speed_test(onnx_model.encode_image,\n",
        "           lambda: np.random.uniform(1, 255, (64, 3, 224, 224))\\\n",
        "                                                .astype(np.float32))"
      ],
      "metadata": {
        "id": "kyF8lyTXnwCz",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "d675b77b-7979-44e6-f7d9-45013a1b17b8"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0.28517956733703614"
            ]
          },
          "metadata": {},
          "execution_count": 17
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "speed_test(onnx_model.encode_text,\n",
        "           lambda: np.stack([np.random.randint(1, 255, (64, 77)),\n",
        "                             np.random.randint(0, 2, (64, 77))]))"
      ],
      "metadata": {
        "id": "AmShwsCtoYte",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "9cd94020-d813-4ddd-cd74-cb6d7d922930"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0.012344837188720703"
            ]
          },
          "metadata": {},
          "execution_count": 18
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## [Speed test] Compare Pytorch and ONNX"
      ],
      "metadata": {
        "id": "zejMPUDCB2Mi"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import random\n",
        "import torch\n",
        "import time\n",
        "\n",
        "def set_seed():\n",
        "    torch.manual_seed(12)\n",
        "    torch.cuda.manual_seed(12)\n",
        "    np.random.seed(12)\n",
        "    random.seed(12)\n",
        "\n",
        "    torch.backends.cudnn.deterministic=True"
      ],
      "metadata": {
        "id": "HqLSjsiGCJXW"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "n = 20\n",
        "model = model.to(device)\n",
        "\n",
        "clip_results = {\"encode_image\": [],\n",
        "                \"encode_text\": []}\n",
        "\n",
        "onnx_results = {\"encode_image\": [],\n",
        "                \"encode_text\": []}\n",
        "                \n",
        "for batch in [2, 8, 16, 32, 64]:\n",
        "    set_seed()\n",
        "    result = speed_test(onnx_model.encode_image,\n",
        "                        lambda: np.random.uniform(1, 255, (batch, 3, 224, 224))\\\n",
        "                        .astype(np.float32), n=n)\n",
        "    result = round(result, 3)\n",
        "    onnx_results[\"encode_image\"].append([batch, result])\n",
        "    print(\"onnx\", batch, \"encode_image\", result)\n",
        "\n",
        "    set_seed()\n",
        "    with torch.inference_mode():\n",
        "        result = speed_test(model.encode_image,\n",
        "                            lambda: torch.randint(1, 255, (batch, 3, 224, 224))\\\n",
        "                            .to(device), n=n)\n",
        "        result = round(result, 3)\n",
        "    print(\"torch\", batch, \"encode_image\", result)\n",
        "    clip_results[\"encode_image\"].append([batch, result])\n",
        "\n",
        "    set_seed()\n",
        "    result = speed_test(onnx_model.encode_text,\n",
        "                        lambda: np.stack([np.random.randint(1, 255, (batch, 77)),\n",
        "                                          np.random.randint(0, 2, (batch, 77))]),\n",
        "                        n=n)\n",
        "    result = round(result, 3)\n",
        "    onnx_results[\"encode_text\"].append([batch, result])\n",
        "    print(\"onnx\", batch, \"encode_text\", result)\n",
        "\n",
        "    set_seed()\n",
        "    with torch.inference_mode():\n",
        "        result = speed_test(model.encode_text,\n",
        "                            lambda: (torch.randint(1, 255, (batch, 77)).to(device),\n",
        "                                     torch.randint(0, 2, (batch, 77)).to(device)),\n",
        "                            is_text=True, n=n)\n",
        "        result = round(result, 3)\n",
        "    print(\"torch\", batch, \"encode_text\", result)\n",
        "    clip_results[\"encode_text\"].append([batch, result])\n",
        "\n",
        "    print(\"-\" * 78)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "YILIR6qMB_eb",
        "outputId": "95e2c9a0-26bb-4203-f0e5-50589f44ddaf"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "onnx 2 encode_image 0.011\n",
            "torch 2 encode_image 0.018\n",
            "onnx 2 encode_text 0.001\n",
            "torch 2 encode_text 0.003\n",
            "------------------------------------------------------------------------------\n",
            "onnx 8 encode_image 0.035\n",
            "torch 8 encode_image 0.01\n",
            "onnx 8 encode_text 0.002\n",
            "torch 8 encode_text 0.003\n",
            "------------------------------------------------------------------------------\n",
            "onnx 16 encode_image 0.07\n",
            "torch 16 encode_image 0.01\n",
            "onnx 16 encode_text 0.004\n",
            "torch 16 encode_text 0.003\n",
            "------------------------------------------------------------------------------\n",
            "onnx 32 encode_image 0.145\n",
            "torch 32 encode_image 0.012\n",
            "onnx 32 encode_text 0.007\n",
            "torch 32 encode_text 0.004\n",
            "------------------------------------------------------------------------------\n",
            "onnx 64 encode_image 0.294\n",
            "torch 64 encode_image 0.013\n",
            "onnx 64 encode_text 0.014\n",
            "torch 64 encode_text 0.005\n",
            "------------------------------------------------------------------------------\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "import pandas as pd\n",
        "\n",
        "pd.DataFrame({\"backend\": [\"onnx\", \"torch\"] * 5,\n",
        "              \"batch\": [2, 2, 8, 8, 16, 16, 32, 32, 64, 64],\n",
        "              \"encode_image\": [j[1] for i in zip(onnx_results[\"encode_image\"],\n",
        "                                              clip_results[\"encode_image\"]) for j in i],\n",
        "              \"encode_text\": [j[1] for i in zip(onnx_results[\"encode_text\"],\n",
        "                                              clip_results[\"encode_text\"]) for j in i]})"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 362
        },
        "id": "WAWUKqQOGd-2",
        "outputId": "725a771f-1b75-4e3a-afa8-7ee7c9caac1f"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "\n",
              "  <div id=\"df-66ec7fd2-693a-4295-b7bb-d5a196f03b9b\">\n",
              "    <div class=\"colab-df-container\">\n",
              "      <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>backend</th>\n",
              "      <th>batch</th>\n",
              "      <th>encode_image</th>\n",
              "      <th>encode_text</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>onnx</td>\n",
              "      <td>2</td>\n",
              "      <td>0.011</td>\n",
              "      <td>0.001</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>torch</td>\n",
              "      <td>2</td>\n",
              "      <td>0.018</td>\n",
              "      <td>0.003</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>onnx</td>\n",
              "      <td>8</td>\n",
              "      <td>0.035</td>\n",
              "      <td>0.002</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>torch</td>\n",
              "      <td>8</td>\n",
              "      <td>0.010</td>\n",
              "      <td>0.003</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>onnx</td>\n",
              "      <td>16</td>\n",
              "      <td>0.070</td>\n",
              "      <td>0.004</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>torch</td>\n",
              "      <td>16</td>\n",
              "      <td>0.010</td>\n",
              "      <td>0.003</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>onnx</td>\n",
              "      <td>32</td>\n",
              "      <td>0.145</td>\n",
              "      <td>0.007</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>torch</td>\n",
              "      <td>32</td>\n",
              "      <td>0.012</td>\n",
              "      <td>0.004</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>onnx</td>\n",
              "      <td>64</td>\n",
              "      <td>0.294</td>\n",
              "      <td>0.014</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>torch</td>\n",
              "      <td>64</td>\n",
              "      <td>0.013</td>\n",
              "      <td>0.005</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "      <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-66ec7fd2-693a-4295-b7bb-d5a196f03b9b')\"\n",
              "              title=\"Convert this dataframe to an interactive table.\"\n",
              "              style=\"display:none;\">\n",
              "        \n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
              "    <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
              "  </svg>\n",
              "      </button>\n",
              "      \n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      flex-wrap:wrap;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "      <script>\n",
              "        const buttonEl =\n",
              "          document.querySelector('#df-66ec7fd2-693a-4295-b7bb-d5a196f03b9b button.colab-df-convert');\n",
              "        buttonEl.style.display =\n",
              "          google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "        async function convertToInteractive(key) {\n",
              "          const element = document.querySelector('#df-66ec7fd2-693a-4295-b7bb-d5a196f03b9b');\n",
              "          const dataTable =\n",
              "            await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                     [key], {});\n",
              "          if (!dataTable) return;\n",
              "\n",
              "          const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "            '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "            + ' to learn more about interactive tables.';\n",
              "          element.innerHTML = '';\n",
              "          dataTable['output_type'] = 'display_data';\n",
              "          await google.colab.output.renderOutput(dataTable, element);\n",
              "          const docLink = document.createElement('div');\n",
              "          docLink.innerHTML = docLinkHtml;\n",
              "          element.appendChild(docLink);\n",
              "        }\n",
              "      </script>\n",
              "    </div>\n",
              "  </div>\n",
              "  "
            ],
            "text/plain": [
              "  backend  batch  encode_image  encode_text\n",
              "0    onnx      2         0.011        0.001\n",
              "1   torch      2         0.018        0.003\n",
              "2    onnx      8         0.035        0.002\n",
              "3   torch      8         0.010        0.003\n",
              "4    onnx     16         0.070        0.004\n",
              "5   torch     16         0.010        0.003\n",
              "6    onnx     32         0.145        0.007\n",
              "7   torch     32         0.012        0.004\n",
              "8    onnx     64         0.294        0.014\n",
              "9   torch     64         0.013        0.005"
            ]
          },
          "metadata": {},
          "execution_count": 21
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "onnx_df = pd.DataFrame({\"ONNX\": [\"RuCLIPtiny\"] * 5,\n",
        "              \"batch\": [2, 8, 16, 32, 64],\n",
        "              \"encode_image\": [i[1] for i in onnx_results[\"encode_image\"]],\n",
        "              \"encode_text\": [i[1] for i in onnx_results[\"encode_text\"]]})\n",
        "onnx_df[\"total\"] = onnx_df[\"encode_image\"] + onnx_df[\"encode_text\"]\n",
        "\n",
        "print(onnx_df.to_markdown(index=False))"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "ol9_RiUoG34e",
        "outputId": "82be9e0e-b92e-4e3c-8132-9269eb22a41d"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "| ONNX       |   batch |   encode_image |   encode_text |   total |\n",
            "|:-----------|--------:|---------------:|--------------:|--------:|\n",
            "| RuCLIPtiny |       2 |          0.011 |         0.001 |   0.012 |\n",
            "| RuCLIPtiny |       8 |          0.035 |         0.002 |   0.037 |\n",
            "| RuCLIPtiny |      16 |          0.07  |         0.004 |   0.074 |\n",
            "| RuCLIPtiny |      32 |          0.145 |         0.007 |   0.152 |\n",
            "| RuCLIPtiny |      64 |          0.294 |         0.014 |   0.308 |\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "clip_df = pd.DataFrame({\"TORCH\": [\"RuCLIPtiny\"] * 5,\n",
        "              \"batch\": [2, 8, 16, 32, 64],\n",
        "              \"encode_image\": [i[1] for i in clip_results[\"encode_image\"]],\n",
        "              \"encode_text\": [i[1] for i in clip_results[\"encode_text\"]]})\n",
        "clip_df[\"total\"] = clip_df[\"encode_image\"] + clip_df[\"encode_text\"]\n",
        "print(clip_df.to_markdown(index=False))"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "qw8ZK9XeG4LY",
        "outputId": "326b24f9-9d21-47ed-d62c-d7594e786b96"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "| TORCH      |   batch |   encode_image |   encode_text |   total |\n",
            "|:-----------|--------:|---------------:|--------------:|--------:|\n",
            "| RuCLIPtiny |       2 |          0.018 |         0.003 |   0.021 |\n",
            "| RuCLIPtiny |       8 |          0.01  |         0.003 |   0.013 |\n",
            "| RuCLIPtiny |      16 |          0.01  |         0.003 |   0.013 |\n",
            "| RuCLIPtiny |      32 |          0.012 |         0.004 |   0.016 |\n",
            "| RuCLIPtiny |      64 |          0.013 |         0.005 |   0.018 |\n"
          ]
        }
      ]
    }
  ]
}